<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let obj = {
      name:'why',
      age:18,
      address:'广州市',
    }
    let _name = obj.name
    Object.defineProperty(obj,'name',{
      set:function(newValue){
        console.log("给name设置了新的值",newValue)
        _name = newValue
      },
      get:function(){
        console.log("获取name的值")
        return _name
      }
    })
    console.log(obj.name)
    obj.name = '吃老虎'
    // 不能监听新增、删除属性
  </script>
</body>
</html>